﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace BigPang.Net
{
    public class Client<T>
    {
        public static T Connect(string ip, object callback, string name)
        {
            NetTcpBinding binding = new NetTcpBinding();
            binding.ReceiveTimeout = TimeSpan.MaxValue;
            binding.SendTimeout = TimeSpan.MaxValue;
            binding.CloseTimeout = TimeSpan.MaxValue;
            binding.ReliableSession.Enabled = true;
            binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 5, 0);
            binding.ReliableSession.Ordered = true;
            binding.Security.Mode = SecurityMode.None;

            DuplexChannelFactory<T> factory = new DuplexChannelFactory<T>(new InstanceContext(callback), binding, new EndpointAddress("net.tcp://" + ip + ":8000/" + name));
            return factory.CreateChannel();
        }
    }
}
